package com.example.zluserservice.service.impl;

import com.example.zluserservice.client.RoleFeignClient;
import com.example.zluserservice.common.constant.UserCacheConstant;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * @Author zhenliu（孙凌岳）
 * @Description Spring的缓存基于AOP代理实现，同一个类内部的方法调用不会经过代理，导致缓存失效
 * @Date 2025/6/19 11:34
 * @Version 1.0
 */
@Service
public class UserCacheService {
    private final RoleFeignClient roleFeignClient;

    public UserCacheService(RoleFeignClient roleFeignClient) {
        this.roleFeignClient = roleFeignClient;
    }


    @Cacheable(value = UserCacheConstant.USER_DATA_SCOPE_LIST,
            key = "'all'",
            cacheManager = "cacheManager30Minutes")
    public List<Long> getNormalUserIds() {
        return roleFeignClient.getUserIdsByRoleCode("user");
    }
}